//
//  XMPhotoView.m
//  XMWeibo
//
//  Created by chi on 14-8-27.
//  Copyright (c) 2014年 xiaoming. All rights reserved.
//

#import "XMPhotoView.h"

#import "UIImageView+WebCache.h"

#import "XMPhoto.h"

@interface XMPhotoView ()

/** 当配图是gif图片时，显示gif标志 */
@property (nonatomic, weak) UIImageView *gifView;

@end

@implementation XMPhotoView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 设置属性
        self.userInteractionEnabled = YES;
        
        
        /** 添加gif标志 */
        UIImageView *gifView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"timeline_image_gif"]];
        self.gifView = gifView;
        [self addSubview:gifView];
        
        
        
    }
    return self;
    
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)setPhoto:(XMPhoto *)photo
{
    _photo = photo;
    
    if ([photo.thumbnail_pic hasSuffix:@"gif"]) {
        self.gifView.hidden = NO;
    }
    else {
        self.gifView.hidden = YES;
    }
    
    [self sd_setImageWithURL:[NSURL URLWithString:photo.thumbnail_pic] placeholderImage:[UIImage imageNamed:@"timeline_image_placeholder"]];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.gifView.layer.anchorPoint = CGPointMake(1.0, 1.0);
    self.gifView.layer.position = CGPointMake(self.bounds.size.width, self.bounds.size.height);
}

@end
